//
//  ShellPledgeViewModel.m
//  ShellWallert
//
//  Created by lvzhao on 2019/9/27.
//  Copyright © 2019年 VV. All rights reserved.
//

#import "ShellPledgeViewModel.h"

@implementation ShellPledgeViewModel

/**
 Convert 请求质押
 */
- (void)pledgeData{
    
    [LZNetworkingManager lz_request:@"get" url:kPledgePreInfo params:nil success:^(id  _Nullable responseObject) {
        
        if([responseObject[kResultStatus] isEqualToString:kCode]){
            self.pledgeModel = [ShellPledgeModel mj_objectWithKeyValues:responseObject[kResultData]];
        }
        [self.reloadSubject sendNext:@(1)];
    } failure:^(NSError * _Nullable error) {
        
    } notwork:^(NSError * _Nullable error) {
        
    } isLoading:YES isFailTip:YES];
    
}


/**
 Convert 开始质押
 */
- (void)pledgeNumber:(NSString *)number
            password:(NSString *)password{
    
    NSDictionary *params = @{@"amount":number?:@"0",
                             @"payPassword":password?:@""};
    
    ///质押成功. 应该返回上页面
    [LZNetworkingManager lz_request:@"post" url:kPledge params:params success:^(id  _Nullable responseObject) {
        if([responseObject[kResultStatus] isEqualToString:kCode]){
            showDelayedDismissTitle(LZLocalizedString(@"质押成功"), nil);
            dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.8 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
                          [LZTool.currentViewController.navigationController popViewControllerAnimated:YES];
            });
            
        }
    } failure:^(NSError * _Nullable error) {

    } notwork:^(NSError * _Nullable error) {

    } isLoading:YES isFailTip:YES];

}


/**
 Convert  收益说明
 */
- (void)getProfitInfo{
    
   ///质押成功. 应该返回上页面
   [LZNetworkingManager lz_request:@"get" url:kProfitInfo params:nil success:^(id  _Nullable responseObject) {
       if([responseObject[kResultStatus] isEqualToString:kCode]){
           NSArray *dataArray = responseObject[kResultData];
           for (int i = 0; i < dataArray.count; i++) {
                ShellIncomeStatementModel *statementModel = [ShellIncomeStatementModel mj_objectWithKeyValues:dataArray[i]];
               [self.dataArray addObject:statementModel];
           }
           [self.reloadSubject sendNext:@(1)];
       }
   } failure:^(NSError * _Nullable error) {
       
   } notwork:^(NSError * _Nullable error) {

    } isLoading:YES isFailTip:YES];
    
}
@end
